﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>条码档案信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script type="text/html" id="barDemo">
        <a title="数据明细" href="javascript:;" lay-event="view"><i class="layui-icon">&#xe647;</i></a>
    </script>

</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <div class="layui-inline layui-show-xs-block">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" id="tempCode" name="tempCode" placeholder="临时编码" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-filter="btnQuery" id="btnQuery" type="button" onclick="loadTempData()"><i class="layui-icon">&#xe615;</i>查询</button>
                                    <button class="layui-btn" lay-filter="btnSubmit" id="btnSubmit" type="button" onclick="saveTemp()"><i class="layui-icon">&#xe672;</i>提交</button>
                                </div>
                            
                            </div>
                    </div>
                    
                    <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" id="happenDate" name="happenDate" placeholder="发生日期" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="wareHouse" id="wareHouse" lay-filter="wareHouse" lay-search="">
                                        <option value="">选择仓库</option>
                                    </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="huowei" id="huowei" class="huowei">
                                        <option value="">仓库货位</option>
                                    </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="dept" id="dept">
                                        <option value="">选择部门</option>
                                    </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="sflx" id="sflx" lay-search="">
                                        <option value="">收发类型</option>
                                    </select>
                                </div>
                            
                                <input type="hidden" name="svalue" id="svalue" />
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-filter="sreach" id="userSearch" type="button" onclick="sureChoose()"><i class="layui-icon">&#xe605;</i>确认选择</button>
                                </div>
                            </form>
                          

                         </div>

                    <div class="layui-card-body ">
                        <div class="layui-inline layui-show-xs-block">
                            <form id="bqForm" class="layui-form layui-col-space5">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" id="spec" name="spec" placeholder="规格货号" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" id="pusers" name="pusers" placeholder="生产人员" class="layui-input">
                                </div>
                
                                <input type="hidden" name="barStatus" id="barStatus" value="need-in" />

                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-filter="btnQuery" id="btnQuery" type="button" onclick="loadData()"><i class="layui-icon">&#xe615;</i>查询</button>
                                </div>
                               
                            </form>

                        </div>
                    </div>

                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-hide" id="list" lay-filter="list"></table>

                        </div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="tlist" lay-filter="tlist"></table>
                    </div>
                    </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>
    /**
    数据加载
    **/
    function loadData() {
        var sdata = JSON.stringify(FormToJson("bqForm"));
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
              { type: 'checkbox' }
            , { field: 'barCode', title: '条码', width: 130 }
            , { field: 'proCode', title: '存货编码', width: 110, }
            , { field: 'proName', title: '存货名称', width: 150 }
            , { field: 'spec', title: '规格型号', width: 130 }
            , { field: 'c_mishu', title: '米数', width: 100 }
            , { field: 'c_gongjin', title: '公斤数', width: 100 }
            , { field: 'plCode', title: '关联计划', width: 90 }
            , { field: 'outCompanyName', title: '客 户', width: 150 }
            , { field: 'barStatusName', title: '条码状态', width: 90 }
            , { field: 'relationBar', title: '关联条码', width: 120 }
            , { field: 'pusers', title: '生产人员', width: 120 }
            ]], done: function (res, curr, count) {
             
            }
            , height: 450
            , url: "../Bar/GetDataList?dataType=barIn&condition=" + sdata
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [30, 40, 50]
            , limit: 40 //每页默认显示的数量
            });
            //监听工具条

            table.on('checkbox(list)', function (obj) {
                var data = obj.data;
                //为父窗口input赋值
                $("#svalue").val("");
                var checkStatus = table.checkStatus('list');
                var codes = "";
                for (var i = 0; i < checkStatus.data.length; i++) {
                    codes += checkStatus.data[i].barCode + ",";
                }
                $("#svalue").val(codes.substr(0, codes.length - 1));
            });
        });
    }
    /**
    加载临时数据
    **/
    function loadTempData() {
      var tempCode= 1+"-"+$("input[ name='tempCode']").val();
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#tlist'
            , cols: [[ //标题栏
              { field: 'tempCode', title: '临时编码', width: 100 }
            , { field: 'proCode', title: '存货编码', width: 110, }
            , { field: 'proName', title: '存货名称', width: 110, }
            , { field: 'spec', title: '规格货号', width: 110, }
            , { field: 'spec', title: '规格货号', width: 110, }
            , { field: 'gongjin', title: '主计量数', width: 100 }
            , { field: 'mishu', title: '辅助计量数', width: 100 }
            , { field: 'barCount', title: '件数', width: 100, }
            , { field: 'id', title: '选择条码', width: 110, }
            , { field: 'right', title: '操作', toolbar: '#barDemo', width: 90, fixed: 'right' }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
            }
            , height: 350
            , url: "../Bar/GetDataList?dataType=tsb&condition=" + tempCode
            , skin: 'row' //表格风格
            , even: true
            , page: false //是否显示分页
            });
            //监听工具条
            table.on('tool(tlist)', function (obj) {
                var data = obj.data;
               if (obj.event == 'view') {
                   url = "../Bar/TempBars?tempCode=" + data.tempCode + "&proCode=" + data.proCode + "&spec=" + data.spec + "&xilie=" + data.c_xilie + "&companyName=" + data.outCompanyName;
                   OpenPage("扫码明细(" + data.tempCode + ")", url);
                   loadTempData();
                } 
                
              
            });

        });
    }

    $(function () {
        //获取列表
        WareHouseSelect("wareHouse");
        loadDept();
        loadData();
        loadShouFa("103");
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(wareHouse)', function (data) {
                WareHuoWei(data.value);
            });
            form.render();
        });
    })
    layui.use(['laydate'], function () {
        var $ = layui.$;
        var laydate = layui.laydate;
        var nowTime = new Date().valueOf();
        var max = null;
        var start = laydate.render({
            elem: '#happenDate',
            trigger: 'click',
            type: 'date',
            format: 'yyyy-MM-dd',
            btns: ['clear', 'confirm'],
            done: function (value, date) {

            }
        });
    })
    /**
    部门信息
    **/
    function loadDept(fileName) {
        $.ajax({
            url: "../System/GetDeptInfo",
            dataType: "json",
            type: "POST",
            async: false,
            success: function (rsl) {
                if (rsl.Result) {
                    var reData = rsl.Data;
                    for (var i = 0; i < reData.length; i++) {
                        $("#dept").append("<option value='" + reData[i].depCode + "'>" + reData[i].depName + "(" + reData[i].depCode + ")" + "</option>");
                    }
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        })
    }
    /**
    收发类型
   **/
    function loadShouFa(dValue) {
        $.ajax({
            url: "../Basis/ShouFaInfo",
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.Result) {
                    var reData = rsl.Data;
                    for (var i = 0; i < reData.length; i++) {
                        $("#sflx").append("<option value='" + reData[i].code + "'>" + reData[i].name + "(" + reData[i].code + ")" + "</option>");
                    }
                    if (dValue != undefined && dValue != "") {
                        $("#sflx  option[value='" + dValue + "'] ").attr("selected", true);
                    }
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        })
    }
    /**
    确认选择
    **/
    function sureChoose() {
        var tempCode = $("input[ name='tempCode']").val();
        if (tempCode == "") {
            layer.msg("请先输入临时编码"); return;
        }
        var value = $("#svalue").val();
        if (value == "") {
            layer.msg("没有选择任何数据"); return;
        } else {
   
                var datas = JSON.stringify(FormToJson("qForm"));
                $.ajax({
                    url: "../Bar/ChooseInWareTemp",
                    type: "post",
                    async: false,
                    data: { datas: datas, tempCode: tempCode,hwName: $("#huowei option:selected").text() },
                    success: function (rsl) {
                        if (rsl.Result) {
                            layer.msg("选择成功！");
                            loadData();
                            loadTempData();
                        } else {
                            layer.msg(rsl.Message);
                        }
                    }
                });
        }

    }
    /**
    货位信息
    **/
    function WareHuoWei(wareCode, dValue) {
        $("#huowei").empty();
        $.ajax({
            url: "../Basis/GetWareHousePosition",
            type: "POST",
            data: { wareCode: wareCode },
            success: function (data) {
                if (data.Result) {
                    var datas = data.Data;
                    for (var i = 0; i < datas.length; i++) {
                        $("#huowei").append("<option value=\"" + datas[i]["code"] + "\" >" + datas[i]["name"]  + "</option>");
                    }
                    if (dValue != undefined && dValue != "") {
                        $("#huowei  option[value='" + dValue + "'] ").attr("selected", true);
                    }
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        });
    }
    /**
    提交扫码入库
    **/
    function saveTemp() {
        //入库类型为1
        var tempCode = 1+"-"+$("input[ name='tempCode']").val();
        if (tempCode == "") {
            layer.msg("请先输入临时编码"); return;
        }
        $.ajax({
            url: "../Bar/SaveInOutData",
            type: "post",
            data: { tempCode: tempCode},
            success: function (rsl) {
                if (rsl.Result) {
                    layer.msg(JSON.stringify(rsl.Data));
                    loadData();
                    loadTempData();
                } else {
                    layer.msg(rsl.Message);
                }
            }
        });
    }
  
</script>